package com.deer.wms.ware.task.model.pushErp;

import com.deer.wms.ware.task.model.SO.SoDetail;
import com.deer.wms.ware.task.model.SO.SoMaster;
import com.deer.wms.ware.task.model.enums.ErpType;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: xu
 * @Date: 2022/06/17/11:46
 * @Description:
 */
@Component
public class StrategyErpService implements ApplicationContextAware {
    private Map<ErpType, AbstractPushErpBean> iFileStrategyMap = new ConcurrentHashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, AbstractPushErpBean> tmepMap = applicationContext.getBeansOfType(AbstractPushErpBean.class);

        tmepMap.values().forEach(strategyService -> iFileStrategyMap.put(strategyService.gainType(), strategyService));
    }


    public Map<String,String> resolveSo(SoMaster soMaster, List<SoDetail> children ) {
        ErpType erpType = new ErpType(soMaster.getBillType(), soMaster.getSoType());
        AbstractPushErpBean iFileStrategy = iFileStrategyMap.get(erpType);
        if (iFileStrategy != null) {
            iFileStrategy.sendERP(soMaster, children);
        }
        return null;
    }

}
